﻿<%@ Page MasterPageFile="~/Site.Master" Language="C#" AutoEventWireup="true" CodeBehind="ConfirmOrder.aspx.cs" Inherits="RabbitShop.UI.ConfirmOrder" %>

<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
    
    <form id="form1" action="../Action/CartSet.aspx" method="POST">
        
    <script src="//code.jquery.com/jquery-1.10.2.js"></script>

    <script type="text/javascript">
        
        function selectAddress(index) {
            var xhr = new XMLHttpRequest();
            xhr.open("post", "/Action/OrderAddress.aspx?aid=" + index, true);
            xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');

            xhr.send();
        }
        
        function SubmitOrder() {
            var uid = getCookie("Id");
            if (uid == "") {
                window.location = "UserLogon.aspx";
                return;
            }
            var data = {};

            var xhr = new XMLHttpRequest();
            xhr.open(form1.method, form1.action, true);
            xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');

            xhr.send(JSON.stringify(data));

            xhr.onloadend = function () {
                if (xhr.responseText == "true") {
                    //window.location = "ConfirmOrder.aspx";
                } else {
                    alert(xhr.responseText);
                }
            };
        }
    </script>
    
    <section class="contact">
        <header>
            <h3>Order:</h3>
        </header>

        
        <table>
    
            <asp:Repeater runat="server" ID="addressRepeater" >
                <ItemTemplate>
                <tr>
                    <td>
                        <input type="radio" id="address<%#Container.ItemIndex %>" name="selectedAddressIndex" onclick="selectAddress(<%#Container.ItemIndex%>);"  />
                    </td>
                                
                    <td>
                        <%#Eval("Province") %>
                    </td>
                    <td>
                        <%#Eval("City") %>
                    </td>
                    <td>
                        <%#Eval("Region") %>
                    </td>
                    <td>
                        <%#Eval("Detail") %>
                    </td>
                            
                    <td>
                        <%#Eval("ContactName") %>
                    </td>
                    <td>
                        <%#Eval("ContactPhone") %>
                    </td>
                    <td>
                        <%#Eval("PostalCode") %>
                    </td>

                </tr>
                </ItemTemplate>
            </asp:Repeater>
                
        </table>
            
        <table>
            <tr>
                <td>商品</td>
                <td>名称</td>
                <td>标题</td>
                <td>单价</td>
                <td>数量</td>
                <td>小计</td>
            </tr>

            <asp:Repeater runat="server" ID="myRepeater"  >
                <ItemTemplate>
                    <tr>
                        <td style="width: 100px;">
                            <a href="ProductDetail.aspx?id=<%#Eval("ItemInfo.ProductId") %>" target="_blank" >
                                <img alt="产品图片" width="100" src="../Images/accent.png" />
                            </a>
                        </td>
                        <td style="width: 100px;">
                            <%#Eval("ProductInfo.Name") %>
                        </td>
                        <td style="width: 350px;">
                            <div>
                                <%#Eval("ProductInfo.Title") %>
                            </div>
                            <div>
                                <%#Eval("ProductInfo.SubTitle") %>
                            </div>
                        </td>
                        <td style="width: 50px;">
                            <%#Eval("ProductInfo.PricePerUnit") %>
                        </td>
                        <td style="width: 50px;">
                            <%#Eval("ItemInfo.Quantity") %>
                        </td>
                        <td style="width: 50px;">
                            <%#(decimal)Eval("ProductInfo.PricePerUnit") * (int)Eval("ItemInfo.Quantity") %>
                        </td>
                    </tr>
                </ItemTemplate>
            </asp:Repeater>
        </table>
            
        <div>
            <div style="float: right;">
                <table style="text-align: right;">
                    <tr>
                        <td style="height: 30px;">数量总计：</td>
                        <td><%=CartTotal.TotalNumber %></td>
                        <td style="text-align: left;">件</td>
                    </tr>
                    <tr>
                        <td style="height: 30px;">重量总计：</td>
                        <td><%=CartTotal.TotalWeight %></td>
                        <td>kg</td>
                    </tr>
                    <tr>
                        <td style="height: 30px;"><strong>商品总价</strong>(不含运费)：</td>
                        <td><span>￥<strong id="Strong1"><%=CartTotal.TotalPrice %></strong></span></td>
                        <td>元</td>
                    </tr>
                    <tr>
                        <td style="height: 30px;"><strong>运费</strong>：</td>
                        <td><span>￥<strong id="Strong2"><%=CartTotal.TotalPrice %></strong></span></td>
                        <td>元</td>
                    </tr>
                </table>
                
                <div style="float: right; width: 173px;background: #f40 none repeat scroll 0 0;
border-color: #f40;

border-radius: 2px;
border-style: solid;
border-width: 1px;
cursor: pointer;
display: block;
font-family: Hiragino Sans GB,microsoft yahei,sans-serif;
font-size: 16px;
height: 38px;
line-height: 38px;
text-align: center;">
            <a data-spm-click="gostr=/tbdetail;locaid=d2"  class="J_LinkAdd" title="加入购物车" href="javascript:SubmitOrder();"
                style="color: #fff;" >
                <i class="tb-iconfont" style=" font-size: 18px;
font-style: normal;
font-weight: 400;
margin-right: 10px;
vertical-align: bottom;">ŭ</i>
                        确认下单
                    </a>
                </div>
            </div>
        </div>
        
    </section>
        
<script type="text/javascript">
function check() {
    document.getElementById("address<%=selectedIndex%>").checked = true;
}
function uncheck() {
    document.getElementById("address<%=selectedIndex%>").checked = false;
}

$(document).ready(check());
</script>
    </form>
</asp:Content>